﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using TfsGiggle.Core;
using System.Collections.ObjectModel;
using Microsoft.VisualStudio.Shell;

namespace TfsGiggle.Search
{
    /// <summary>
    /// Interaction logic for TfsGiggleWorkitemControl.xaml
    /// </summary>
    public partial class TfsGiggleWorkitemControl : UserControl
    {
        private ObservableCollection<TfsGiggleWorkitem> _tfsGiggleWorkitems = new ObservableCollection<TfsGiggleWorkitem>();

        /// <summary>
        /// ctor
        /// </summary>
        public TfsGiggleWorkitemControl()
        {
            InitializeComponent();
        }

        /// <summary>
        /// The search results
        /// </summary>
        public ObservableCollection<TfsGiggleWorkitem> TfsGiggleWorkitems
        {
            get
            {
                return _tfsGiggleWorkitems;
            }
        }

        /// <summary>
        /// Open the document
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ListViewHandleDoubleClick(object sender, MouseButtonEventArgs e)
        {
            try
            {
                var item = (TfsGiggleWorkitem)((ListViewItem)sender).Content;
                TfsGiggleSearchPackage.Instance.ViewArtifact(item.TeamProjectCollectionId, item.Id, item.GetType());
            }
            catch (Exception ex)
            {
                ActivityLog.LogError("Exception caught in TfsGiggle", ex.ToString());
                throw;
            }
        }
    }
}
